package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;
import cn.edu.cqupt.cxcy.dto.InvestorImpl;
import cn.edu.cqupt.cxcy.model.Investor;
import cn.edu.cqupt.cxcy.model.Project;
import cn.edu.cqupt.cxcy.util.SendMail;

/**
 * Servlet implementation class InveSloveMail
 */
public class InveSloveMail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InveSloveMail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println(123);
        request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		HttpSession session=request.getSession();
		List<Object> list=(List<Object>)session.getAttribute("user");
		String id=request.getParameter("id");
		int inve_id=(Integer)list.get(1);
		Project show=new InvestorImpl().WhileShowOfOneProject(Integer.parseInt(id));
		Map<String,String> one=new InvestorImpl().returnTeamname(show.getTe_id());
	   String teamname=new InvestorImpl().returnTeamName(show.getTe_id());
	   Investor inve=new InvestorImpl().returnInvestor(inve_id);
	   one.put("inve_email", inve.getI_loname());
	   one.put("inve_name", inve.getI_name());
	   one.put("inve_tel", inve.getI_tel());
	   one.put("pro_name", show.getP_name());
	   one.put("t_name", teamname);
	   boolean flag=new SendMail().Congilre(one);
	   JSONObject jsonObject = JSONObject.fromObject(flag);
	   PrintWriter out= response.getWriter();
		out.print(jsonObject.toString());
	}

}
